package com.zzq.my.jetpacks.jectpackapp.ui.stickyheaderrecyclerview;

import android.view.View;
import android.widget.TextView;

import com.zzq.my.jetpacks.jectpackapp.R;

import tellh.com.stickyheaderview_rv.adapter.StickyHeaderViewAdapter;
import tellh.com.stickyheaderview_rv.adapter.ViewBinder;

public class ItemHeaderViewBinder extends ViewBinder<HeaderItem, ItemHeaderViewBinder.ViewHolder> {
    @Override
    public ViewHolder provideViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }
    @Override
    public void bindView(StickyHeaderViewAdapter adapter, ViewHolder holder, int position, HeaderItem entity) {
        holder.tv_title.setText(entity.title);
        holder.button.setTextColor(entity.color);
        holder.button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (entity.color == -0xafb0) {
                    entity.color = -0x888889;
                } else {
                    entity.color = -0xafb0;
                }
                adapter.notifyItemChanged(position);
            }
        });
    }
    @Override
    public int getItemLayoutId(StickyHeaderViewAdapter adapter) {
        return R.layout.header_view;
    }
    static class ViewHolder extends ViewBinder.ViewHolder {
        TextView button;
        TextView tv_title;
        public ViewHolder(View rootView) {
            super(rootView);
            this.tv_title = (TextView) rootView.findViewById(R.id.tv_title);
            this.button = (TextView) rootView.findViewById(R.id.button);
        }
    }
}